package com.hjq.service.impl;

import com.hjq.common.PageResult;
import com.hjq.entity.po.Topic;
import com.hjq.mapper.TopicMapper;
import com.hjq.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class TopicServiceImpl implements TopicService {

    @Autowired
    private TopicMapper topicMapper;

    @Override
    public PageResult<Topic> findAll() {
        List<Topic> list=topicMapper.findAll();
        Long total = topicMapper.total();

        return new PageResult<Topic>(list,total);
    }

    @Override
    public Integer add(Topic topic) {
        topic.setStatus((byte) 0);
        topic.setDelFlag((byte) 0);
        topic.setCreatedAt(LocalDateTime.now());
        topic.setUpdatedAt(LocalDateTime.now());
        return topicMapper.add(topic);
    }

    @Override
    public Integer deleteById(Integer id) {
        return topicMapper.deleteById(id);

    }

    @Override
    public Integer update(Topic topic) {
        return topicMapper.update(topic);
    }
}
